package week6;

import java.io.*;

/**
 * @author The Setting sun
 * @create 2021-10-14 15:10
 */
public class Work3 {
    public static void main(String[] args) throws IOException {
        File file = new File("hello.txt");
//        file.createNewFile();
        RandomAccessFile raf = new RandomAccessFile(file, "rw");
        raf.write("*".getBytes());
        System.out.println(raf.getFilePointer());
        raf.write("我爱Java".getBytes());
        System.out.println(raf.getFilePointer());
        raf.write("*".getBytes());
        System.out.println(raf.getFilePointer());

        raf.seek(0);
        byte[] buffer = new byte[1024];
        int len;
        while ((len = raf.read(buffer)) != -1){
            String str = new String(buffer, 0, len);
            System.out.println(str);
        }

        raf.close();
    }
}
